<template>
  <div class="app-container">
    <el-upload
      class="upload-demo"
      drag
      action="http://127.0.0.1:5000/upload_data"
      multiple
      :on-change="on_change"
      :on-success="on_success"
      :data="{token:token}">
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div class="el-upload__tip" slot="tip">只能上传json/csv文件</div>
    </el-upload>

  </div>
</template>

<script>
export default {

  data() {
    return {
      token: ""
    }
  },
  created () {
      var key = encodeURIComponent('/auth/info')
      this.$data.token = this.getCookie(key)
  },
  methods: {
    on_change(file, fileList){
      var key = encodeURIComponent('/auth/info')
      this.$data.token = this.getCookie(key)
    },
    on_success(response, file, fileList){
      console.log(response.message)
      this.$message({
            message: response.message,
            type: "success",
          });
    },
    getCookie(name) {
      var arr;
      var reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
      if ((arr = document.cookie.match(reg))) 
        return unescape(arr[2]);
      else 
        return null; document.cookie = name + "=" + escape(value);
    },
  }
}
</script>

